home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / Q-R / RIFF File Format / RIFFmain.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-06  |  5.0 KB  |  248 lines  |  [TEXT/KAHL]

  1. /*
  2. MOD 07-12-87 MAZ - RIFF I/O driver mainline
  3. */
  4. #include <Quickdraw.h>
  5. #include <WindowMgr.h>
  6. #include <FontMgr.h>
  7. #include <MenuMgr.h>
  8. #include <EventMgr.h>
  9. #include <DialogMgr.h>
  10. #include <FileMgr.h>
  11. #include <HFS.h>
  12. #include "MAZlib.h"
  13. #include <stdio.h>
  14. #include <xQuickdraw.h>
  15. #include <xWindowMgr.h>
  16. #include "RIFF.h"
  17.  
  18. /* Low Memory Locations that LightSpeed C Doesn't Define */
  19. extern short MenuBarHeight: 0xBAA; /* height of menu bar */
  20.  
  21. extern bool save_as_RIFF();
  22.  
  23. extern short storage_type;
  24.  
  25. Rect drag_limit_rect;
  26. Rect full_screen;
  27.  
  28. MenuHandle apple_menu;
  29. MenuHandle file_menu;
  30.  
  31. char last_file[256];
  32.  
  33. /* in-memory picture definition */
  34. extern unsigned char *body[4];
  35. extern short nrows;
  36. extern short ncols;
  37. extern unsigned char *transfer_table;
  38.  
  39. short desired_nsamples;
  40.  
  41. main()
  42.     {
  43.     short menu_height;
  44.     
  45.     Stdio_MacInit(true);
  46.     /* Macintosh Initialization */
  47.     InitGraf(&thePort);
  48.     InitFonts();
  49.     InitWindows();
  50.     TEInit();
  51.     InitMenus();
  52.     InitDialogs(0);
  53.     InitCursor();
  54.     Click_On(0);
  55.     Init_stdio();
  56.     SetWTitle(FrontWindow(),"\pRIFF I/O Driver");
  57.     /* compute screen rectangle based on size of screen */
  58.     drag_limit_rect = WMgrPort->portRect;
  59.     if (ROM85 == 0)
  60.         menu_height = 20;                    /* assume 20 for old ROM */
  61.     else
  62.         menu_height = MenuBarHeight;        /* in low memory for new ROM */
  63.     drag_limit_rect.top += menu_height;
  64.     full_screen = drag_limit_rect;
  65.     InsetRect(&drag_limit_rect, 4, 4);
  66.     /* set up the menus */
  67.     apple_menu = NewMenu(1, "\p\24");
  68.     AddResMenu(apple_menu, 'DRVR');
  69.     InsertMenu(apple_menu, 0);
  70.     file_menu = NewMenu(2,"\pFile");
  71.     AppendMenu(file_menu, "\pOpen RIFF.../O;Save as RIFF.../S;Quit/Q");
  72.     DisableItem(file_menu, 2);
  73.     body[0] = null;
  74.     InsertMenu(file_menu, 0);
  75.     DrawMenuBar();
  76.     FlushEvents(-1, -1);
  77.     InitCursor();
  78.     forever
  79.         mainevent();
  80.     }
  81.  
  82. mainevent()
  83.     {
  84.     bool b;
  85.     char c;
  86.     WindowPtr window;
  87.     EventRecord event;
  88.  
  89.     SystemTask();
  90.     b = GetNextEvent(everyEvent, &event); 
  91.     switch (event.what)
  92.         {
  93.     case nullEvent:
  94.         break;
  95.     case autoKey:
  96.     case keyDown:
  97.         c = event.message;
  98.         if ((event.modifiers&cmdKey) != 0)
  99.             domenu(MenuKey(c));
  100.         break;
  101.     case updateEvt:
  102.         window = (WindowPtr)event.message;
  103.         BeginUpdate(window);
  104.         EndUpdate(window);
  105.         break;
  106.     case mouseDown:
  107.         domousedown(&event);
  108.         break;
  109.     case mouseUp:
  110.         break;
  111.         }
  112.     }
  113.  
  114. /* process mouse down event */
  115. domousedown(e)
  116. EventRecord *e;
  117.     {
  118.     short i, window_code, ccode, toolsize, sh;
  119.     long growResult;
  120.     WindowPtr w;
  121.     Handle h, h2;
  122.     Rect *r;
  123.     Point pt;
  124.     Rect R;
  125.     char pascal_string[256];
  126.  
  127.     /* see which window the mouse down is in */
  128.     window_code = FindWindow(e->where, &w);
  129.     /* pop windows forward by click here */
  130.     if (w != null && w != FrontWindow())
  131.         {
  132.         SelectWindow(w);
  133.         return;
  134.         }
  135.     /* handle menu hits */
  136.     if (window_code == inMenuBar)
  137.         {
  138.         /* get menu hit and go to it */
  139.         domenu(MenuSelect(e->where));
  140.         /* and we're done */
  141.         return;
  142.         }
  143.     /* handle desk accessories */
  144.     if (window_code == inSysWindow)
  145.         {
  146.         SystemClick(e, w);
  147.         /* and we're done */
  148.         return;
  149.         }
  150.     /* test for drag of a window */
  151.     if (window_code == inDrag)
  152.         {
  153.         /* do the dragging */
  154.         DragWindow(w, e->where, &drag_limit_rect);
  155.         /* and we're done */
  156.         return;
  157.         }
  158.     /* test for goAway of window */
  159.     if (window_code == inGoAway)
  160.         {
  161.         if (TrackGoAway(w, e->where))
  162.             DisposeWindow(w);
  163.         /* and we're done */
  164.         return;
  165.         }
  166.     /* test for in zoom box (new ROM) */
  167.     if (window_code == inZoomIn || window_code == inZoomOut)
  168.         {
  169.         /* Track the Zoom Box */
  170.         if (TrackBox(w, e->where, window_code))
  171.             /* Zoom the Window */
  172.             ZoomWindow(w, window_code, false);
  173.         /* done */
  174.         return;
  175.         }
  176.     /* test for grow of edit window */
  177.     if (window_code == inGrow)
  178.         {
  179.         /* grow the edit window */
  180.         growResult = GrowWindow(w, e->where, &drag_limit_rect);
  181.         /* adjust size of window if needed */
  182.         if (growResult)
  183.             SizeWindow(w, LoWord(growResult), HiWord(growResult), true);
  184.         /* and we're done */
  185.         return;
  186.         }
  187.     }
  188.  
  189. domenu(menu_result)
  190. long menu_result;
  191.     {
  192.     short menu_id, item_number, sh, r, nsam,
  193.       x_pic_aspect, y_pic_aspect, width, height;
  194.     DialogPtr dptr;
  195.     Rect R;
  196.     char pascal_string[256];
  197.     char filename[256];
  198.  
  199.     menu_id = HiWord(menu_result);
  200.     item_number = LoWord(menu_result);
  201.     switch (menu_id)
  202.         {
  203.     case 1:
  204.         /* apple menu */
  205.         /* a run-of-the-mill desk accessory */
  206.         GetItem(apple_menu, item_number, pascal_string);
  207.         /* open up the desk accessory */
  208.         r = OpenDeskAcc(pascal_string);
  209.         break;
  210.     case 2:
  211.         switch (item_number)
  212.             {
  213.         case 1:
  214.             /* open riff in maximal precision format */
  215.             open_RIFF(last_file, 256);
  216.             if (body[0] != null)
  217.                 {
  218.                 DisableItem(file_menu, 1);
  219.                 EnableItem(file_menu, 2);
  220.                 printf("RIFF File \42%s\42 read in (%d rows, %d cols)\n",
  221.                   last_file, nrows, ncols);
  222.                 }
  223.             break;
  224.         case 2:
  225.             /* save to RIFF */
  226.             nsam = 65;
  227.             if (storage_type == st_rgb)
  228.                 nsam = 256;
  229.             if (save_as_RIFF(last_file, nsam))
  230.                 {
  231.                 printf("Saved as RIFF File \42%s\42\n", last_file);
  232.                 DisposPtr(body[0]);
  233.                 body[0] = null;
  234.                 DisposPtr(transfer_table);
  235.                 EnableItem(file_menu, 1);
  236.                 DisableItem(file_menu, 2);
  237.                 }
  238.             break;
  239.         case 3:
  240.             HiliteMenu(0);
  241.             ExitToShell();
  242.             break;
  243.             }
  244.         break;
  245.         }
  246.     HiliteMenu(0);
  247.     }
  248.